package com.example.springbootdemo.springEvent;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.math.BigDecimal;

/**
 * @author ：cici
 * @date ：Created in 2019/8/28 13:43
 */
@Slf4j
public class ApplicationEventPublish implements ApplicationContextAware {

    private ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

    public void publishEvent(){
        Order order = new Order();
        order.setAmount(BigDecimal.valueOf(1.1));
        order.setName("茄子");
        order.setNum(2);
        log.info("context" + context.toString());
        context.publishEvent(new EventPublish(order));
    }

}
